<?php
/*
 * Creative Bulletin Board Generation 3
 * Version 1.0 Beta 1
 +------------------------------------
 * Index Modular Handling Script (Frontend)
 * Started: August 22, 2009 10:38:01 AM
 * Script version: 1.1.1
 +------------------------------------
 * Linux Code Testing Done on August 28, 2009 11:28:17 AM (PHP 5.2.6)
 * Windows Code Testing Done on September 19, 2009 08:35:00 PM (PHP 5.2.10)
 */

session_start(); # FIXME: Shouldn't put this here?

// Initialize CBB
define("APP_TYPE", "frontend");

require_once(dirname(__FILE__)."/core/initialize.php");

//------------------------------------
// Are we online?
if($db->conf_value("system_online") != "false"){
	// Modular System
	// Sec... Are we BANNED?
	if(isset($_SESSION["cf_username"])){
		$userController = (isset($userController) ? $userController : unserialize($_SESSION["cf_controller"]));
		if($userController->group->is_banned() == 1){
			// WTF you are really banned... Evil guy. Huh.
			define("APPLICATION", "forums");
			define("MODULE", "index");
			require_once(CORE_PATH."app/application.php");
			$app = new application_system(APP_TYPE, APPLICATION);
			$view->initHeader($lang->getByKey("core.banned"));
			$view->writeIn($view->inlineError($lang->getByKey("core.banned.desc")));
			$view->footer();
			$view->output();
			$go = false;
		}
		else $go = true;
	}
	else $go = true;
	if($go){
		if(isset($_GET["app"])){
			define("APPLICATION", $_GET["app"]);
		}
		else{
			define("APPLICATION", $db->conf_value("default_app_frontend"));
		}
		require_once(CORE_PATH."app/application.php");
		$app = new application_system(APP_TYPE, APPLICATION);
		if(!isset($_GET["module"])){
			define("MODULE", $app->getDefaultModule());
		}
		else{
			define("MODULE", $_GET["module"]);
		}

		//------------------------------------
		// Initialize the Modular System 'n output
		require_once(CORE_PATH."app/module.php");
		$module = new modular_system(APP_TYPE, APPLICATION, MODULE);
		$view->initHeader($module->getModuleTitle());
		// Dummy code, don't uncomment, just used for dev purposes
		$view->writeIn(
			$view->inlineError("Error testing. This is really fun!").
			$view->inlineSuccess("Success testing. This is also fun.").
			$view->inlineInfo("This is just a little bit of information.").
			$view->inlineWarning("This is a warning, and its no fun.")
		);
		// /end
		$view->footer();
		$view->output();
	}
}
else{
	define("APPLICATION", "forums");
	define("MODULE", "index");
	require_once(CORE_PATH."app/application.php");
	$app = new application_system(APP_TYPE, APPLICATION);
	$view->initHeader($lang->getByKey("core.offline"));
	$view->writeIn($view->inlineError($lang->getByKey("core.offline.desc").$db->conf_value("system_off_reason")));
	$view->footer();
	$view->output();
}
